package cn.iocoder.yudao.module.system.dal.mysql.pushManage;

import java.util.*;

import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.module.system.dal.dataobject.pushManage.PushManageDO;
import org.apache.commons.lang3.StringUtils;
import org.apache.ibatis.annotations.Mapper;
import cn.iocoder.yudao.module.system.controller.admin.pushManage.vo.*;
import org.apache.ibatis.annotations.Param;

/**
 * 推送管理 Mapper
 *
 * @author 管理员
 */
@Mapper
public interface PushManageMapper extends BaseMapperX<PushManageDO> {

    default PageResult<PushManageDO> selectPage(PushManagePageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<PushManageDO>()
                .likeIfPresent(PushManageDO::getPushName, reqVO.getPushName())
                .eqIfPresent(PushManageDO::getType, reqVO.getType())
                .eqIfPresent(PushManageDO::getPushObject, reqVO.getPushObject())
                .eq(StringUtils.isNotBlank(reqVO.getPushObjectId()), PushManageDO::getPushObjectId, reqVO.getPushObjectId())
                .eqIfPresent(PushManageDO::getPushModule, reqVO.getPushModule())
                .eqIfPresent(PushManageDO::getStatus, reqVO.getStatus())
                .eqIfPresent(PushManageDO::getActionFrequency, reqVO.getActionFrequency())
                .betweenIfPresent(PushManageDO::getStartTime, reqVO.getBeginStartTime(), reqVO.getEndStartTime())
                .betweenIfPresent(PushManageDO::getEndTime, reqVO.getBeginEndTime(), reqVO.getEndEndTime())
                .likeIfPresent(  PushManageDO::getTitle, reqVO.getTitle())
                .likeIfPresent( PushManageDO::getMessageText, reqVO.getMessageText())
                .eqIfPresent(PushManageDO::getActionNum, reqVO.getActionNum())
                .betweenIfPresent(PushManageDO::getCreateTime, reqVO.getBeginCreateTime(), reqVO.getEndCreateTime())
                .orderBy(PushManageDO.class, PageParam.DEFAULT_SORTING_FIELDS));
    }

    List<PushManageDO> selectListByNowDate(@Param("nowDate")Date nowDate);

    default List<PushManageDO> selectList(PushManageExportReqVO reqVO) {
        return selectList(new LambdaQueryWrapperX<PushManageDO>()
                .likeIfPresent(PushManageDO::getPushName, reqVO.getPushName())
                .eqIfPresent(PushManageDO::getType, reqVO.getType())
                .eqIfPresent(PushManageDO::getPushObject, reqVO.getPushObject())
                .eqIfPresent(PushManageDO::getPushObjectId, reqVO.getPushObjectId())
                .eqIfPresent(PushManageDO::getPushModule, reqVO.getPushModule())
                .eqIfPresent(PushManageDO::getActionFrequency, reqVO.getActionFrequency())
                .betweenIfPresent(PushManageDO::getStartTime, reqVO.getBeginStartTime(), reqVO.getEndStartTime())
                .betweenIfPresent(PushManageDO::getEndTime, reqVO.getBeginEndTime(), reqVO.getEndEndTime())
                .eqIfPresent(PushManageDO::getTitle, reqVO.getTitle())
                .eqIfPresent(PushManageDO::getMessageText, reqVO.getMessageText())
                .eqIfPresent(PushManageDO::getActionNum, reqVO.getActionNum())
                .betweenIfPresent(PushManageDO::getCreateTime, reqVO.getBeginCreateTime(), reqVO.getEndCreateTime())
                .orderByDesc(PushManageDO::getId));
    }

}
